package cn.qn.controller;

import cn.qn.base.PageVO;
import cn.qn.dto.ResponseDTO;
import cn.qn.dto.news.*;
import cn.qn.enums.BooleanEnum;
import cn.qn.service.news.AlbumService;
import cn.qn.service.news.ImageTextService;
import cn.qn.service.news.VideoService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

/**
 * @author: Jeet
 * @date: 2019.07.18
 * @description: 新闻类
 */
@RestController
@RequestMapping("/news")
public class NewsController {

    @Reference(check = false,timeout = 30000)
    private AlbumService albumService;

    @Reference(check = false,timeout = 30000)
    private ImageTextService imageTextService;

    @Reference(check = false,timeout = 30000)
    private VideoService videoService;

    @RequestMapping(value = "/album/page",method = RequestMethod.POST)
    public ResponseDTO albumPage(@RequestBody AlbumQueryDTO query){
        query.setStatus(BooleanEnum.TRUE.getCode());
        PageVO<AlbumDTO> vo = albumService.page(query);
        return ResponseDTO.success(vo);
    }
    @RequestMapping(value = "/album/{id}",method = RequestMethod.GET)
    public ResponseDTO album(@PathVariable Integer id){
        AlbumDTO dto = albumService.findById(id);
        return ResponseDTO.success(dto);
    }


    @RequestMapping(value = "/video/page",method = RequestMethod.POST)
    public ResponseDTO videoPage(@RequestBody VideoQueryDTO query){
        query.setStatus(BooleanEnum.TRUE.getCode());
        PageVO<VideoDTO> vo = videoService.page(query);
        return ResponseDTO.success(vo);
    }
    @RequestMapping(value = "/video/{id}",method = RequestMethod.GET)
    public ResponseDTO video(@PathVariable Integer id){
        VideoDTO dto = videoService.findById(id);
        return ResponseDTO.success(dto);
    }

    @RequestMapping(value = "/imageText/page",method = RequestMethod.POST)
    public ResponseDTO imageTextPage(@RequestBody ImageTextQueryDTO query){
        query.setStatus("1");
        query.setCreateTimeSort(2);
        PageVO<ImageTextDTO> vo = imageTextService.pageQueryImageTexts(query);
        return ResponseDTO.success(vo);
    }
    @RequestMapping(value = "/imageText/{id}",method = RequestMethod.GET)
    public ResponseDTO imageText(@PathVariable Integer id){
        ImageTextDTO dto = imageTextService.queryDetailById(id);
        return ResponseDTO.success(dto);
    }
    @RequestMapping(value = "/imageText/top",method = RequestMethod.GET)
    public ResponseDTO imageText(){
        ImageTextDTO dto = imageTextService.getTop();
        return ResponseDTO.success(dto);
    }

}
